package com.xquant.marketdata.curvestrip.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.xquant.common.core.constant.ErrMsgConstant;
import com.xquant.common.core.exception.ServiceException;
import com.xquant.common.core.web.controller.BaseController;
import com.xquant.common.core.web.domain.AjaxResult;
import com.xquant.common.core.web.page.TableDataInfo;
import com.xquant.common.log.annotation.Log;
import com.xquant.common.log.enums.BusinessType;
import com.xquant.common.security.annotation.RequiresPermissions;
import com.xquant.common.security.utils.ExcelUtil;
import com.xquant.common.security.utils.SecurityUtils;
import com.xquant.marketdata.curvestrip.domain.IrCurveSetDTO;
import com.xquant.marketdata.curvestrip.domain.VolsurfaceDTO;
import com.xquant.marketdata.curvestrip.entity.TvolsurfaceRatesDTO;
import com.xquant.marketdata.curvestrip.service.VolatilityCurveStripService;
import com.xquant.marketdata.utils.CommResponse;
import com.xquant.marketdata.utils.DateUtils;
import com.xquant.marketdata.utils.ResponseVo;
import com.xquant.marketdata.utils.SortUtil;
import com.xquant.system.api.domain.SysUser;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.xquant.common.core.utils.PageUtils.startPage;
import static java.math.BigDecimal.ROUND_HALF_UP;

/**
 * 波动率曲面
 * @Author yunnuo.yang
 */
@RestController
@RequestMapping("volatilityCurveStrip")
public class VolatilityCurveStripController extends BaseController {

    @Autowired
    private VolatilityCurveStripService volatilityCurveStripService;

    final static String msg = "操作成功";


    /**
     * 查询 tvolsurface
     */
    @PreAuthorize("@ss.hasPermi('curve:volcurve:volsurface:list')")
    @RequestMapping(value = "/queryVolatilityCurveByPage.action")
    public PageInfo<VolsurfaceDTO> queryVolatilityCurveByPage(@RequestParam Map<String, Object> param) {
        startPage();
        param.put("userId", SecurityUtils.getUserId());
        PageInfo<VolsurfaceDTO> pageInfo = volatilityCurveStripService.queryVolatilityCurveByPage(param);
        return pageInfo;
    }

    /**
     * 刪除波动率曲綫
     *
     * @param param VLS_CODE
     * @return
     */
    @RequestMapping(value = "/deleteVlsCurve.action")
    @PreAuthorize("@ss.hasPermi('curve:volcurve:volsurface:del')")
    public CommResponse deleteVolatilityCurve(@RequestBody Map<String, Object> param) {
        param.put("userId", SecurityUtils.getUserId());
        volatilityCurveStripService.deleteVolatilityCurve(param);
        return new CommResponse(true, msg);
    }

    /**
     * 新增 VolatilityCurve
     */
    @RequestMapping(value = "/saveVlsCurve.action")
    @PreAuthorize("@ss.hasPermi('curve:volcurve:volsurface:add')")
    public CommResponse insertVolatilityCurve(@RequestBody Map<String, Object> param) {
        param.put("userId", SecurityUtils.getUserId());
        List<VolsurfaceDTO> list = volatilityCurveStripService.checkVolatilityCurve(param);
        if (list.size() >= 1) {
            return new CommResponse(false, "此波动率曲面已存在，请删除后再新增");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"peCode"))){
            param.put("peCode", "PE_SYS_"+param.get("uICode")+"_CURVE");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsType"))){
            param.put("vlsType", "2");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsDaycount"))){
            param.put("vlsDaycount", "Actual/365 (Fixed)");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsStrikeType"))){
            param.put("vlsStrikeType", "22");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsStrikeMethod"))){
            param.put("vlsStrikeMethod", "Linear");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsParam"))){
            param.put("vlsParam", "<?xml version=\"1.0\" encoding=\"GB2312\"?>\n" +
                    "<root>\n" +
                    "  <Parameter>\n" +
                    "    <KeyValues>\n" +
                    "      <!--报价波动率曲面-->\n" +
                    "      <QUOTE_VOLSURFACE DATATYPE=\"STRING\" TYPE=\"SIMPLE\">XQ_VLS_000905_QUOTE_IVS</QUOTE_VOLSURFACE>\n" +
                    "      <!--原始波动率曲面-->\n" +
                    "      <ORIGNAL_VOLSURFACE DATATYPE=\"STRING\" TYPE=\"SIMPLE\">XQ_VLS_000905_FM_IVS</ORIGNAL_VOLSURFACE>\n" +
                    "      <!--标准期限-->\n" +
                    "      <VLS_TERM_ST DATATYPE=\"STRING\" TYPE=\"ARRAY\">\n" +
                    "        <V>1M</V>\n" +
                    "        <V>2M</V>\n" +
                    "        <V>3M</V>\n" +
                    "        <V>6M</V>\n" +
                    "        <V>9M</V>\n" +
                    "        <V>1Y</V>\n" +
                    "      </VLS_TERM_ST>\n" +
                    "      <!--自然期限-->\n" +
                    "      <VLS_TERM DATATYPE=\"STRING\" TYPE=\"ARRAY\">\n" +
                    "        <V>30D</V>\n" +
                    "        <V>60D</V>\n" +
                    "        <V>90D</V>\n" +
                    "        <V>180D</V>\n" +
                    "        <V>270D</V>\n" +
                    "        <V>360D</V>\n" +
                    "      </VLS_TERM>\n" +
                    "      <!--ForwardMoneyness范围左边界-->\n" +
                    "      <VLS_FM_MIN DATATYPE=\"DOUBLE\" TYPE=\"SIMPLE\">0.7</VLS_FM_MIN>\n" +
                    "      <!--ForwardMoneyness范围右边界-->\n" +
                    "      <VLS_FM_MAX DATATYPE=\"DOUBLE\" TYPE=\"SIMPLE\">1.3</VLS_FM_MAX>\n" +
                    "      <!--ForwardMoneyness间隔-->\n" +
                    "      <VLS_FM_INTERVAL DATATYPE=\"DOUBLE\" TYPE=\"SIMPLE\">0.01</VLS_FM_INTERVAL>\n" +
                    "    </KeyValues>\n" +
                    "  </Parameter>\n" +
                    "</root>");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsRatetype"))){
            param.put("vlsRatetype", "0");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsTermMethod"))){
            param.put("vlsTermMethod", "Variance");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"pipeId"))){
            param.put("pipeId", "-1");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsInterpOrder"))){
            param.put("vlsInterpOrder", "ST");
        }
        if(StringUtils.isBlank(MapUtils.getString(param,"vlsAnnualdays"))){
            param.put("vlsAnnualdays", "0");
        }
        param.put("createBy",SecurityUtils.getUserId());

        volatilityCurveStripService.allocateVolSurface(param);

        volatilityCurveStripService.insertVolatilityCurve(param);
        return new CommResponse(true, msg);
    }

    /**
     * 修改 TIRCURVE
     */
    @RequestMapping(value = "/updateVlsCurve.action")
    @PreAuthorize("@ss.hasPermi('curve:volcurve:volsurface:update')")
    public CommResponse updateIrCurveRates(@RequestBody Map<String, Object> param) {
        param.put("userId", SecurityUtils.getUserId());
        param.put("peCode", "PE_SYS_"+param.get("uICode")+"_CURVE");
        volatilityCurveStripService.updateVolatilityCurve(param);
        return new CommResponse(true, msg);
    }

    /**
     * 波动率曲面定义查询导出
     */
    @Log(title = "波动率曲面定义", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('curve:volcurve:volsurface:export')")
    @RequestMapping(value = "/export")
    public void exportSet(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        param.put("userId", SecurityUtils.getUserId());
        PageInfo<VolsurfaceDTO> list = volatilityCurveStripService.queryVolatilityCurveByPage(param);
        ExcelUtil<VolsurfaceDTO> util = new ExcelUtil<VolsurfaceDTO>(VolsurfaceDTO.class);
        util.exportExcel(response, list.getList(), "波动率曲面定义");
    }

    /**
     * 查询 tvolsurface_ref_set
     */
    @RequestMapping(value = "/queryVolatilityCurveRefSetByPage.action")
    public PageInfo<Map> queryVolatilityCurveRefSetByPage(@RequestParam Map<String, Object> param) {
        param.put("userId", SecurityUtils.getUserId());
        PageInfo<Map> pageInfo = volatilityCurveStripService.queryVolatilityCurveRefSetByPage(param);
        return pageInfo;
    }


    /**
     * 新增 tvolsurface_ref_set
     */
    @RequestMapping(value = "/insertVolatilityCurveRefSet.action")
    public CommResponse insertVolatilityCurveRefSet(@RequestParam Map<String, Object> param) {
        param.put("userId", SecurityUtils.getUserId());
        List<Map> list = volatilityCurveStripService.queryVolatilityCurveRefSetByPage(param).getList();
        if (list.size() >= 1) {
            return new CommResponse(false, "此样本点已存在，请删除后再新增");
        }
        volatilityCurveStripService.deleteVolatilityCurveRefSetByDate(param);
        param.put("endDate", "2050-12-31");
        volatilityCurveStripService.insertVolatilityCurveRefSet(param);
        return new CommResponse(true, msg);
    }

    /**
     * 删除 tvolsurface_ref_set
     */
    @RequestMapping(value = "/deletevolatilityCurveRefSet.action")
    public CommResponse deletevolatilityCurveRefSet(@RequestParam Map<String, Object> param) {
        param.put("userId", SecurityUtils.getUserId());

        volatilityCurveStripService.deleteVolatilityCurveRefSetByDate(param);
        return new CommResponse(true, msg);
    }

    @PreAuthorize("@ss.hasPermi('curve:volcurve:hisvolcurve:list')")
    @RequestMapping(value = "/queryVolSurfaceRates.action")
    public ResponseVo queryVolSurfaceRates(@RequestParam Map<String, Object> param) {
        List<Map> list = volatilityCurveStripService.queryVolSurfaceRates(param);
        return volatilityCurveStripService.packageResult(list);
    }

    // 导出波动率曲面分析
    @PreAuthorize("@ss.hasPermi('curve:volcurve:hisvolcurve:export')")
    @RequestMapping(value = "/exportVolSurfaceRates.action")
    public void exportVolSurfaceRates(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        List<Map> list = volatilityCurveStripService.queryVolSurfaceRates(param);
        ResponseVo responseVo = volatilityCurveStripService.packageResult(list);
        HSSFWorkbook sheets = null;
        List<List<String>> resulExport = new ArrayList<>();
        try {
            // 拼接表头
            Map map = (Map) responseVo.getResult();
            List<String> pointList = (List) map.get("pointList");
            List<Map> resultList = (List<Map>) map.get("resultList");
            ArrayList<String> head = new ArrayList<>();
            for (int j = 0; j <= 61; j++) {
                if (j == 0) {
                    head.add("期限/行权价");
                } else {
                    head.add(j + 70 -1 + "%");
                }
            }
            resulExport.add(head);
            //拼接表格内容
            for (int rowIndex = 0; rowIndex < pointList.size(); rowIndex++) {
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add(pointList.get(rowIndex));
                for (int i = 0; i < 61; i++) {
                    BigDecimal vlsRate = (BigDecimal) resultList.get(rowIndex * 61 + i).get("vls_rate");
                    vlsRate = vlsRate.multiply(new BigDecimal(100)).setScale(3, ROUND_HALF_UP);
                    arrayList.add(vlsRate.toString() + "%");
                }
                resulExport.add(arrayList);
            }
            sheets = ExcelUtil.exportVlsExcel("exportVolSurfaceRates", resulExport,62);
        }catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException(ErrMsgConstant.EXPOERT_ERR,e.getMessage());
        }
        ExcelUtil.responseExcel(sheets,"", response);
    }

    @RequestMapping(value = "/getLastDateByVlsCode.action")
    public CommResponse getLastDateByVlsCode(@RequestParam Map<String, Object> param) {
        List<Map> list = volatilityCurveStripService.getLastDateByVlsCode(param);
        return   new CommResponse(true, list);
    }
    @RequestMapping(value = "/queryRealTimeVolSurfaceRates.action")
    public ResponseVo queryRealTimeVolSurfaceRates(@RequestParam Map<String, Object> param) {
        String realTime=MapUtils.getString(param,"refSetTime");
        if(StringUtils.isBlank(realTime)){
            realTime= DateUtils.getCurrentTime();
        }
        param.put("refSetTime",realTime.replaceAll(":",""));
        List<Map> list = volatilityCurveStripService.queryRealTimeVolSurfaceRates(param);
        return volatilityCurveStripService.packageResult(list);
    }
    @RequestMapping(value = "/updateVolSurfaceRates.action")
    public CommResponse updateVolSurfaceRates(@RequestParam Map<String, Object> param) {
        volatilityCurveStripService.updateVolSurfaceRates(param);
        return new CommResponse(true, msg);
    }

    @RequestMapping(value = "/insertVolSurfaceRates.action")
    public CommResponse insertVolSurfaceRates(@RequestParam Map<String, Object> param) {
        volatilityCurveStripService.insertVolSurfaceRates(param);
        return new CommResponse(true, msg);
    }



    @RequestMapping(value = "/deleteVolSurfaceRates.action")
    public CommResponse deleteVolSurfaceRates(@RequestParam Map<String, Object> param) {
        volatilityCurveStripService.deleteVolSurfaceRates(param);
        return new CommResponse(true, msg);
    }

    /**
     * 波动率锥中的历史波动率查询 包含 历史波动率 隐含波动率 行情
     * @param param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('curve:volcurve:hisvolcone:list')")
    @RequestMapping(value = "/queryVolRateForCone.action")
    public ResponseVo queryVolRateForCone(@RequestParam Map<String, Object> param) {
        List<Map> list = volatilityCurveStripService.queryVolRateForCone(param);
        //日期点 横坐标
        List<String> pointList =new ArrayList<>();
        LinkedHashSet<String> s=new LinkedHashSet<String>();
        list.stream().forEach(map ->{s.add(map.get("beg_date").toString());});
        s.stream().forEach(str->pointList.add(str));
        Map<String,List<Map>> resultMapList = new HashMap<>();
        resultMapList.put("vls",list.stream().filter(map->"vls".equals(map.get("type").toString())).collect(Collectors.toList()));
        resultMapList.put("his_vls",list.stream().filter(map->"his_vls".equals(map.get("type").toString())).collect(Collectors.toList()));
        resultMapList.put("quant",list.stream().filter(map->"quant".equals(map.get("type").toString())).collect(Collectors.toList()));
        //期限窗口
        List<String> limitList = new ArrayList<>();
        List<Map> tmpList=new ArrayList<>();
        s.clear();
        tmpList.addAll(resultMapList.get("vls"));
        tmpList.addAll(resultMapList.get("his_vls"));
        tmpList= SortUtil.sortTerm(tmpList, "vls_term", true);
        tmpList.stream().forEach(map -> map.put("vls_term",volatilityCurveStripService.transgetDate(map.get("vls_term").toString())));
        tmpList.stream().forEach(map->{s.add(map.get("vls_term").toString());});
        s.stream().forEach(str->limitList.add(str));
        //数据集合 按期限和日期升序排序
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("pointList",pointList);//日期点 横坐标
        resultMap.put("typeList",Arrays.asList("vls","his_vls","quant")); //类型 隐含:vls 历史:his_vls 行情:quant;
        resultMap.put("limitList",limitList);//期限窗口
        resultMap.put("dataList",resultMapList);//数据集合 Map<List<Map>>
        ResponseVo rvo = new ResponseVo();
        rvo.setResult(resultMap);
        rvo.setErrorCode(0);
        return rvo;
    }
    /**
     * 波动率锥
     * @param param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('curve:volcurve:hisvolcone:list')")
    @RequestMapping(value = "/queryVolCone.action")
    public ResponseVo queryVolCone(@RequestParam Map<String, Object> param) {
        List<Map> list = volatilityCurveStripService.queryVolCone(param);
        LinkedHashSet<String> s=new LinkedHashSet<String>();
        //存放各个期限点对应的波动率数据
        Map<String,List<Map>> resultLimitMap=new HashMap<>();
        list.stream().forEach(map ->{s.add(map.get("vls_term").toString());});
        List<String> pointList=new ArrayList<>();
        for(String limit : s){
            pointList.add(limit);
            List<Map> limitMap=new ArrayList<>();
            list.stream().forEach(map->{
                if(map.get("vls_term").toString().equals(limit)){
                    limitMap.add(map);
                }
            });
            List<Map> limitList=SortUtil.sortListByKey(limitMap,"vls_rate",true);
            //每个期限点存放升序的波动率数据
            resultLimitMap.put(limit,limitList);
        }
        List<String> typeList = new ArrayList<String>();
        Collections.addAll(typeList,"Min","10分位","25分位","50分位","75分位","90分位","Max","Latest");
        List<String> tmpTypeList= Arrays.asList("Min","10分位","25分位","50分位","75分位","90分位","Max","Latest");
        //存放对应分位点各个期限的波动率数据
        List<Map<String,List<Map>>> resultMapList=new ArrayList<>();
        for (String type: tmpTypeList) {
            List<Map> tmpResultList=new ArrayList<>();
            Map<String,List<Map>> tmpMap=new HashMap<>();
            for (String limit:pointList) {
                if(type.equals("Min")){
                    tmpResultList.add(resultLimitMap.get(limit).get(0));
                }else if (type.equals("Max")){
                    tmpResultList.add(resultLimitMap.get(limit).get(resultLimitMap.get(limit).size()-1));
                }else if("10分位".equals(type)){
                    tmpResultList.add(resultLimitMap.get(limit).get( (int)(resultLimitMap.get(limit).size()*0.1) ));
                }else if("25分位".equals(type)){
                    tmpResultList.add(resultLimitMap.get(limit).get( (int)(resultLimitMap.get(limit).size()*0.25) ));
                }else if("50分位".equals(type)){
                    tmpResultList.add(resultLimitMap.get(limit).get( (int)(resultLimitMap.get(limit).size()*0.5) ));
                }else if("75分位".equals(type)){
                    tmpResultList.add(resultLimitMap.get(limit).get( (int)(resultLimitMap.get(limit).size()*0.75) ));
                }else if("90分位".equals(type)){
                    tmpResultList.add(resultLimitMap.get(limit).get( (int)(resultLimitMap.get(limit).size()*0.9) ));
                }else if("Latest".equals(type)){
                    List<Map> tmp= resultLimitMap.get(limit).stream().filter(map-> {
                        return map.get("beg_date").toString().equals(param.get("endDate").toString());
                    }).collect(Collectors.toList());
                    if(tmp.size()>0){
                        tmpResultList.add(tmp.get(0));
                    }
                }
            }
            if(tmpResultList.size()>0){
                tmpMap.put(type,tmpResultList);
                resultMapList.add(tmpMap);
            }else{
                typeList.remove(type);
            }
        }
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("pointList",pointList);
        resultMap.put("typeList",typeList);
        resultMap.put("dataList",resultMapList);
        ResponseVo rvo = new ResponseVo();
        rvo.setResult(resultMap);
        rvo.setErrorCode(0);
        return rvo;
    }

    @PreAuthorize("@ss.hasPermi('marketdata:curve:import')")
    @PostMapping("/importCurve")
    public CommResponse importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil util = new ExcelUtil();
        logger.info(file.getOriginalFilename());
        List<List<Object>> importResultList = util.importExcelNormal(file.getInputStream());
        //2022-07-21 botao.yu 按研究部最新的excel结构 需要转换成实体再走原逻辑
        List<TvolsurfaceRatesDTO> list =transferVlsList(importResultList);
        HashMap<String, Set<String>> map = new HashMap<>();
        HashSet<String> set = new HashSet<>();
        list.stream().forEach(vls->{
            set.add(vls.getVlsCode());
        });
        list.stream().forEach(vls->{
            if(set.contains(vls.getVlsCode())){
                if (map.get(vls.getVlsCode())==null) {
                    map.put(vls.getVlsCode(),new HashSet<String>());
                }
                map.get(vls.getVlsCode()).add(vls.getBegDate());
            }
        });
        volatilityCurveStripService.deleteVolSurfaceRatesList(map);
        list = volatilityCurveStripService.getLastVolSurfaceRates(map, list);
        boolean flag = volatilityCurveStripService.insertVolSurfaceRatesList(list);
        if (!flag) {
            return CommResponse.success("导入失败");
        }
        return CommResponse.success("导入成功");
    }

    private static interface ImportVlsDTO{
        public static final int VLS_CODE=0;
        public static final int BEG_DATE=1;
        public static final int VLS_TERM_ST=2;
        public static final int VLS_TERM=3;
        public static final int SPOT=4;
        public static final int FORWARD=5;
        //行权价/波动率起始列
        public static final int DATA_BEG=7;
    }

    private List<TvolsurfaceRatesDTO>  transferVlsList(List<List<Object>> list){
        List<TvolsurfaceRatesDTO> resultList=new ArrayList<>();
        if(list.size()<1){
            return  resultList;
        }
        for(int i=0;i<list.size();i=i+2){
            List<Object> strikeRow=list.get(i);
            List<Object> vlsRateRow=list.get(i+1);
            if(strikeRow.size()<8||vlsRateRow.size()<8) {
                   throw new ServiceException(ErrMsgConstant.IMPORT_ERROR);
            }
            for(int j=7;j<strikeRow.size();j++) {
                if (StrUtil.isEmpty(strikeRow.get(j).toString()) || StrUtil.isEmpty(vlsRateRow.get(j).toString())) {
                    //直接跳出 进入下一行数据
                    break;
                }
                TvolsurfaceRatesDTO volDto = new TvolsurfaceRatesDTO();
                volDto.setVlsCode(strikeRow.get(ImportVlsDTO.VLS_CODE).toString());
                if (strikeRow.get(ImportVlsDTO.BEG_DATE) instanceof Date) {
                    volDto.setBegDate(DateUtil.format((Date) strikeRow.get(ImportVlsDTO.BEG_DATE),"yyyy-MM-dd"));
                }
                if (strikeRow.get(ImportVlsDTO.BEG_DATE) instanceof String) {
                    volDto.setBegDate((String) strikeRow.get(ImportVlsDTO.BEG_DATE));
                }
                volDto.setVlsTerm(strikeRow.get(ImportVlsDTO.VLS_TERM).toString());
                volDto.setVlsTermSt(strikeRow.get(ImportVlsDTO.VLS_TERM_ST).toString());
                volDto.setVlsUTerm("0D");
                volDto.setVlsOptType("P");
                volDto.setVlsOptStyle("1");
                volDto.setVlsDeltaType("1");
                volDto.setVlsStrike(new BigDecimal(strikeRow.get(j).toString()));
                volDto.setVlsRate(new BigDecimal(vlsRateRow.get(j).toString()));
                resultList.add(volDto);
            }
        }
        return resultList;
    }
    @PreAuthorize("@ss.hasPermi('marketdata:curve:add')")
    @PostMapping(value = "/addTvolsurfaceRatesDTO.action")
    public CommResponse addTvolsurfaceRatesDTO(@RequestBody TvolsurfaceRatesDTO form)
    {
        form.setVlsOptType("P");
        form.setVlsOptStyle("1");
        form.setVlsDeltaType("1");
        form.setVlsAtmType("1");
        form.setImpTime(DateUtils.getCurr_YYYY_MM_DD_HH_MM_SS());
        form.setVlsTermSt(form.getVlsTermSt().toUpperCase(Locale.ROOT));
        boolean flag = volatilityCurveStripService.insertVolSurfaceRates2(form);
        if (!flag) {
            return CommResponse.failure("新增波动率失败，存在相同数据！");
        }
        return CommResponse.success();
    }

    @PreAuthorize("@ss.hasPermi('marketdata:curve:update')")
    @PostMapping(value = "/updateTvolsurfaceRatesDTO.action")
    public CommResponse updateTvolsurfaceRatesDTO(@RequestBody TvolsurfaceRatesDTO form)
    {
        form.setVlsTermSt(form.getVlsTermSt().toUpperCase(Locale.ROOT));
        volatilityCurveStripService.updateVolSurfaceRate(form);
        return CommResponse.success();
    }

//    @RequestMapping(value = "/exportVolsurfaceRates.action")
//    @PreAuthorize("@ss.hasPermi('curve:volsurfaceRates:export')")
//    public Object exportVolsurfaceRates(@RequestBody Map<String, Object> params) {
//        volatilityCurveStripService.updateSurfaceAuthority(params);
//        return CommResponse.success("修改成功");
//    }

    @RequestMapping(value = "/updateSurfaceAuthority.action")
    @PreAuthorize("@ss.hasPermi('curve:ircurve:allocate')")
    public Object updateSurfaceAuthority(@RequestBody Map<String, Object> params) {
        volatilityCurveStripService.updateSurfaceAuthority(params);
        return CommResponse.success("修改成功");
    }


    /**
     * 查询波动率曲线下拉列表
     */
    @RequestMapping(value = "/queryVolSurfaceCombox.action")
    @ResponseBody
    public PageInfo<VolsurfaceDTO> queryVolSurfaceCombox(HttpServletRequest request) {
        Map<String, Object> params = new WeakHashMap<>();
        params.put("condition", request.getParameter("query"));
        if (StringUtils.isBlank(request.getParameter("query"))) {
            params.put("condition", request.getParameter("condition"));
        }
        params.put("userId",SecurityUtils.getUserId());
        return volatilityCurveStripService.queryVolatilityCurveByPage(params);

    }

}
